/**
 * 1.页面有多个需要共享状态，引入vuex，便于维护 （非父子通信）
 * 2. 缓存部分异步数据，减少后端服务的访问，增加用户体验
 */

import axios from "axios";

const CinemaModule = {
    namespaced:true,//开启命名空间
    state() {
        return {
            cinemaList: []
        }
    },
    //唯一修改状态的位置，只能同步
    mutations: {
        changeCinemaList(state, payload) {
            state.cinemaList = payload
        }
    },
    //同步+异步
    actions: {
        async getCinemaList(store, payload) {
            console.log(payload)
            let res = await axios({
                url: "https://m.maizuo.com/gateway?cityId=110100&ticketFlag=1&k=7147275",
                headers: {
                    'X-Client-Info': '{"a":"3000","ch":"1002","v":"5.2.1","e":"1700982879663830145269761"}',
                    'X-Host': 'mall.film-ticket.cinema.list',
                }
            })
            // console.log(res.data.data.cinemas)
            //提交mutations
            store.commit("changeCinemaList", res.data.data.cinemas)
        }
    },
    getters: {
        filterCinemaList(state) {
            return (payload) => {
                return state.cinemaList.filter(item => item.eTicketFlag === payload)
            }
        }
    }
}

export default CinemaModule